home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / FRM_ALRT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-15  |  8.1 KB  |  297 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <VDI.H>
  9. #include <OSBIND.H>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "XA_TYPES.H"
  13. #include "XA_GLOBL.H"
  14. #include "XA_DEFS.H"
  15. #include "BOX3D.H"
  16. #include "FRM_ALRT.H"
  17. #include "K_DEFS.H"
  18. #include "RESOURCE.H"
  19. #include "OBJECTS.H"
  20. #include "WATCHBOX.H"
  21. #include "C_WINDOW.H"
  22. #include "STD_WIDG.H"
  23. #include "system.h"
  24. #include "watchbox.h"
  25. #include "frm_util.h"
  26.  
  27. /*
  28.     Form_alert handler v2.1
  29. */
  30. short click_alert_widget(XA_WINDOW *wind, XA_WIDGET *widg);
  31.  
  32. short do_form_alert(short default_button, char *alert, short owner)
  33. {
  34.     XA_WINDOW *alert_window;
  35.     XA_WIDGET_LOCATION dialog_toolbar_loc={LT,3,20};
  36.     short x,y,w,h=0,n_lines=0,n_buttons=0,icon,max_w=0,m_butt_w=0;
  37.     short ty,th,b;
  38.     short f,pnt[10];
  39.     char alert_text[5][100];    /* texts to display in the alert */
  40.     char button_text[3][20];    /* text for buttons */
  41.     short button_w[3];
  42.     char *t;
  43.     OBJECT *alert_form;
  44.     OBJECT *alert_icons;
  45.  
  46.     DIAGS(("called do_form_alert()\n"));
  47.  
  48.     for(ty=0; ty<5; ty++) alert_text[ty][0]='\0';
  49.     
  50.     if (alert[0]!='[') return 0;
  51.     t=alert+1;
  52.     for(f=1; (t[f]!=']')&&(t[f]!='\0'); f++);    /* Search for closing bracket on first field */
  53.     if (t[f]!=']') return 0;
  54.  
  55.     DIAGS(("1\n"));
  56.  
  57.     t[f]='\0';
  58.     icon=atoi(t);                /* calculate the icon */
  59.     
  60.     t+=f+1;
  61.     if (t[0]!='[') return 0;
  62.  
  63.     DIAGS(("2\n"));
  64.     
  65.     t++;
  66.     for(f=0; (t[f]!=']')&&(t[f]!='\0');f++)        /* Strip out the text lines */
  67.     {
  68.         if (t[f]=='|')
  69.         {
  70.             t[f]='\0';
  71.             vqt_extent(V_handle,t,pnt);
  72.             w=pnt[2]-pnt[0];
  73.             th=pnt[7]-pnt[1];
  74.             h+=th;
  75.             if (w>max_w) max_w=w;
  76.             sprintf(alert_text[n_lines],"%s",t);
  77.             n_lines++;
  78.             t+=f+1; f=0;
  79.         }
  80.     }
  81.     if (t[f]!=']') return 0;
  82.     t[f]='\0';
  83.     vqt_extent(V_handle,t,pnt);
  84.     w=pnt[2]-pnt[0];
  85.     th=pnt[7]-pnt[1];
  86.     h+=th;
  87.     if (w>max_w) max_w=w;
  88.     sprintf(alert_text[n_lines],"%s",t);
  89.     n_lines++;
  90.  
  91.     DIAGS(("3\n"));
  92.  
  93.     t+=f+1;
  94.     if (t[0]!='[') return 0;
  95.     t++;
  96.  
  97.     DIAGS(("4\n"));
  98.  
  99.     for(f=0; (t[f]!=']')&&(t[f]!='\0');f++)        /* Strip out the text lines */
  100.     {
  101.         if (t[f]=='|')
  102.         {
  103.             t[f]='\0';
  104.             vqt_extent(V_handle,t,pnt);
  105.             button_w[n_buttons]=pnt[2]-pnt[0]+3*display.c_max_w;
  106.             m_butt_w+=button_w[n_buttons];
  107.             sprintf(button_text[n_buttons],"%s",t);
  108.             n_buttons++;
  109.             t+=f+1; f=0;
  110.         }
  111.     }
  112.     if (t[f]!=']') return 0;
  113.     t[f]='\0';
  114.     vqt_extent(V_handle,t,pnt);
  115.     button_w[n_buttons]=pnt[2]-pnt[0]+3*display.c_max_w;
  116.     m_butt_w+=button_w[n_buttons];
  117.     sprintf(button_text[n_buttons],"%s",t);
  118.     n_buttons++;
  119.     
  120.     DIAGS(("5\n"));
  121.     
  122.     
  123.     if (m_butt_w>max_w) max_w=m_butt_w;
  124.     
  125.     w=max_w + 50;
  126.     
  127.     h+=5*th;
  128.     x=(display.w-w)/2;
  129.     y=(display.h-h)/2;
  130.  
  131. /* Create a copy of the alert box template */
  132.     alert_form=CloneForm(ResourceTree(system_resources,ALERT_BOX));
  133.     alert_icons=ResourceTree(system_resources,ALERT_ICONS);
  134.     alert_form->ob_width=w;
  135.     alert_form->ob_x=x;
  136.     alert_form->ob_y=y;
  137.  
  138.     if ( display.colours<16 )            /* hmm... perhaps this should be done in */
  139.     {                                    /* "color mode" too? <mk> */
  140.         long obspec=(long)alert_form->ob_spec;
  141.         obspec &= ~0xfL ;
  142.         obspec |= (display.dial_colours.bg_col & 0xf);    /* interior color */
  143.         alert_form->ob_spec = (void*)obspec;
  144.     }
  145.  
  146.     for(f=ALR_IC_DRIVE; f<=ALR_IC_BOMB; f++)
  147.     {
  148.         ((ICONBLK*)(alert_icons+f)->ob_spec)->ib_xicon=((ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec)->ib_xicon;
  149.         ((ICONBLK*)(alert_icons+f)->ob_spec)->ib_yicon=((ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec)->ib_yicon;
  150.     }
  151.     
  152.     switch(icon)    /* Setup the correct icon for this alert */
  153.     {
  154.         case 1:
  155.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_WARNING)->ob_spec;
  156.             break;
  157.         case 2:
  158.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_QUESTION)->ob_spec;
  159.             break;
  160.         case 3:
  161.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_STOP)->ob_spec;
  162.             break;
  163.         case 4:
  164.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_INFO)->ob_spec;
  165.             break;
  166.         case 5:
  167.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_DRIVE)->ob_spec;
  168.             break;
  169.         case 6:
  170.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_BOMB)->ob_spec;
  171.             break;
  172.         case 0:
  173.         default:
  174.             (ICONBLK*)(alert_form+ALERT_D_ICON)->ob_spec=(ICONBLK*)(alert_icons+ALR_IC_SYSTEM)->ob_spec;
  175.             break;
  176.     }
  177.     
  178.     for(f=0; f<5; f++)                /* Fill in texts */
  179.         sprintf(((TEDINFO*)alert_form[ALERT_T1+f].ob_spec)->te_ptext,"%s",alert_text[f]);
  180.     
  181.     x=w-m_butt_w;                     /* space the buttons evenly */
  182.     b=x/(n_buttons+1);    
  183.     x=b;
  184.     
  185.     for(f=0; f<n_buttons; f++)        /* Fill in & show buttons */
  186.     {
  187.         if ( display.colours<16 )
  188.         {
  189.             /* Make sure we can *READ* the button text: */
  190.             alert_form[ALERT_BUT1+f].ob_flags &= ~FLD3DANY ;    /* clear 3D flags */
  191.             /* (this is just a stopgag measure - apparently the 3D button code
  192.                 isn't quite mono-compatible yet...) */
  193.         }
  194.         sprintf((char*)alert_form[ALERT_BUT1+f].ob_spec,"%s",button_text[f]);
  195.         alert_form[ALERT_BUT1+f].ob_width=button_w[f];
  196.         alert_form[ALERT_BUT1+f].ob_x=x;
  197.         alert_form[ALERT_BUT1+f].ob_flags&=~(HIDETREE|DEFAULT);
  198.         alert_form[ALERT_BUT1+f].ob_state=0;
  199.         x+=button_w[f]+b;
  200.     }
  201.     
  202.     if (default_button)                /* Set the default button if it was specified */
  203.         alert_form[ALERT_BUT1+default_button-1].ob_flags|=DEFAULT;
  204.     
  205.     for(f=n_buttons; f<3; f++)        /* Hide unused buttons */
  206.         alert_form[ALERT_BUT1+f].ob_flags|=HIDETREE;
  207.  
  208. /* Create a window and attach the alert object tree to it */
  209.     alert_window=create_window(owner, NAME|MOVE|STORE_BACK|NO_WORK, alert_form->ob_x, alert_form->ob_y, 
  210.                                     alert_form->ob_width+10, display.c_max_h+16+alert_form->ob_height);
  211.  
  212.     dialog_toolbar_loc.y=display.c_max_h+10;
  213.     set_toolbar_widget(alert_window, dialog_toolbar_loc, alert_form);
  214.     
  215. /* Change the click & drag behaviours for the alert box widget, because alerts return a number */
  216. /* 1 to 3, not an object index. */
  217.     alert_window->widgets[XAW_TOOLBAR].behaviour[XACB_CLICK]=&click_alert_widget;
  218.     alert_window->widgets[XAW_TOOLBAR].behaviour[XACB_DRAG]=&click_alert_widget;
  219.     ((XA_WIDGET_TREE*)alert_window->widgets[XAW_TOOLBAR].stuff)->owner=owner;
  220.     
  221.     alert_window->active_widgets|=NO_REDRAWS;    /* We don't want any redraw messages  */
  222.                                             /* - the widget handler will take care of it */
  223.     alert_window->is_open=TRUE;
  224.  
  225. /* Set the window title to be the clients name to avoid confusion */
  226.     alert_window->widgets[XAW_TITLE].stuff=(void*)clients[owner].name;
  227.     
  228.     v_hide_c(V_handle);
  229.     pull_wind_to_top(alert_window);
  230.     display_window(alert_window);
  231.     v_show_c(V_handle,1);
  232.     
  233.     DIAGS(("opened alert\n"));
  234.     
  235.     return 0;
  236. }
  237.  
  238. /*
  239.     Small handler for clicks on an alert box
  240. */
  241. short click_alert_widget(XA_WINDOW *wind, XA_WIDGET *widg)
  242. {
  243.     short x,y,sel_b=-1,f,b;
  244.     unsigned long retv=XA_OK;
  245.     XA_WIDGET_TREE *wt=(XA_WIDGET_TREE*)widg->stuff;
  246.     OBJECT *alert_form;
  247.     GRECT r;
  248.     XA_WINDOW *wl;
  249.     
  250.     if (window_list!=wind)            /* You can only work alerts when they are on top */
  251.         return FALSE;
  252.  
  253.     alert_form=wt->tree;
  254.  
  255.     rp_2_ap(wind, widg, &x, &y);    /* Convert relative coords and window location to absolute screen location */
  256.  
  257.     f=find_object(alert_form, 0, 10, x+widg->click_x, y+widg->click_y);
  258.  
  259.     if (((f>=ALERT_BUT1)            /* Did we click on a valid button? */
  260.         &&(f<ALERT_BUT1+3))
  261.         &&(!(alert_form[f].ob_flags&HIDETREE)))
  262.     {
  263.         clear_clip();
  264.     
  265.         b=watch_object(alert_form, f, SELECTED, 0);
  266.     
  267.         if (b)
  268.             sel_b=f+1-ALERT_BUT1;
  269.     
  270.         if (sel_b>-1)                    /* If the click was definite, we return the button & close the window */
  271.         {
  272.             if (wt->owner!=AESpid)
  273.             {
  274.                 clients[wt->owner].waiting_pb->intout[0]=sel_b;
  275.                 Fwrite(clients[wt->owner].clnt_pipe_wr, (long)sizeof(unsigned long),&retv);    /* Write success to clients reply pipe to unblock the process */
  276.             }
  277.  
  278.             wl=wind->next;
  279.  
  280.             r.g_x=wind->x;    r.g_y=wind->y;
  281.             r.g_w=wind->w;    r.g_h=wind->h;
  282.  
  283.             wind->is_open=FALSE;
  284.             send_wind_to_bottom(wind);
  285.             delete_window(wind);
  286.  
  287.             v_hide_c(V_handle);
  288.             display_windows_below(&r,wl);
  289.             v_show_c(V_handle,1);
  290.             
  291.             DeleteClone(alert_form);    /* Delete this copy of the alert form */
  292.         }
  293.     }
  294.     
  295.     return FALSE;
  296. }
  297.